package com.zhuimeng.elasticsearchdemo.controller;

import com.zhuimeng.elasticsearchdemo.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@Controller
public class PositionController {
    @Autowired
    private PositionService positionService;

    @RequestMapping("/")
    public String index(){
        return "index";
    }

    @GetMapping("/search/{keyword}/{pageNo}/{pageSize}")
    @ResponseBody
    public List<Map<String,Object>> searchPosition(@PathVariable("keyword") String  keyword, @PathVariable("pageNo")int pageNo,
                                                   @PathVariable("pageSize")int  pageSize)throws IOException {
        List<Map<String,Object>> list = positionService.searchPos(keyword, pageNo, pageSize);
        return  list;
    }

    @RequestMapping("/importAll")
    @ResponseBody
    public String importAll(){
        try{
            positionService.importAll();
        }catch (Exception e){
            e.printStackTrace();
        }
        return "success";
    }
}
